package poker;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

public class PersonalSettingsGUI extends DefaultSettingsPanelGUI {
	
	private JTextField nameText = new JTextField(10);
	private JLabel nameLabel = new JLabel("Player name");
	
	private JButton ok = new JButton("OK");
	private JButton cancel = new JButton("Cancel");
	private JButton apply = new JButton("Apply");
	private HoofdSchermGUI hui;
	
	private SettingsGUI sg;
	
	public PersonalSettingsGUI(SettingsGUI sg)
	{	
		this.hui = sg.getHoofdScherm();
		this.sg = sg;
		setLayout(new BorderLayout());
		JPanel setPanel1 = new JPanel();
		//JPanel setPanel2 = new JPanel();
				
		try {
			Properties p = new Properties();
			p.load( new FileInputStream("settings.ini") );
			nameText.setText(p.getProperty("Nick"));
		}
		catch(IOException e) {}
		
		setPanel1.add(nameLabel);
		setPanel1.add(nameText);
		
		add(setPanel1, BorderLayout.CENTER);
		//add(setPanel2, BorderLayout.SOUTH);
	}
	
	public boolean ok()
	{
		if(!nameText.getText().matches("\\w{1,15}"))
		{
			JOptionPane.showMessageDialog(this, "This is not a valid name");
			return false;
		}
		try {
			Properties p = new Properties();
			p.load( new FileInputStream("settings.ini") );
			p.setProperty("Nick", nameText.getText());
			p.store( new FileOutputStream("settings.ini"), "" );
			hui.client.spel.sr.zoekDeelname(hui.client.deelname.speler.spelerId).speler.setNaam(nameText.getText());	
			hui.speler.setNaam(nameText.getText());
			hui.tafel.spelerTafels.get(hui.speler.spelerId).setLastAction();
			hui.validate();
			hui.repaint();
			//hui.client.up();
		}
		catch(IOException e) {}
		return true;
	}
	
	public void cancel()
	{
		
	}
}
